package com.ddyx.util;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;

public class MQSessionUtil {
	
	private static Session session = null;
	private static String brokerURL = "tcp://120.27.20.74:61616";
	private static ConnectionFactory factory;
	private static Connection connection;
	
	public static Session getSession() throws Exception {
		if(session == null) {
			init();
		}
		return session;
	}
	
	private static void init() throws Exception{
		factory = new ActiveMQConnectionFactory(brokerURL);
		connection = factory.createConnection();
		connection.start();
		session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	}

}
